/*
 * Copyright (c) 2010 MoSync AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef MAINTERPETER_ABSTRACTINTERPRETER_H
#define MAINTERPETER_ABSTRACTINTERPRETER_H

#include "ClockIntervalUpdateListener.h"
#include "InterpreterErrorListener.h"

namespace MAInterpreter
{

/**
 * Super class for interpreters. The protocol of this class
 * is intended to be an interpreter-independent interface
 * that can be used when implementing different languages.
 */
class AbstractInterpreter
{
public:
	AbstractInterpreter();
	virtual ~AbstractInterpreter();

	virtual int initialize() = 0;
	virtual void close() = 0;
	virtual int eval(const char* script) = 0;

	virtual void onTouchDown(int x, int y, int touchId) = 0;
	virtual void onTouchUp(int x, int y, int touchId) = 0;
	virtual void onTouchDrag(int x, int y, int touchId) = 0;
	virtual void onKeyDown(int keyCode, int nativeKeyCode) = 0;
	virtual void onKeyUp(int keyCode, int nativeKeyCode) = 0;
	virtual void onCustomEvent(MAEvent* event) = 0;
	virtual void onClose() = 0;

	virtual void setDispatchEvents(bool dispatch);
	virtual bool AbstractInterpreter::getDispatchEvents();

	virtual void setInterpreterErrorListener(
			InterpreterErrorListener* listener);
	virtual void reportInterpreterError(const char* errorMessage);

	virtual void setScreenLeft(int x) { screenLeft = x; }
	virtual void setScreenTop(int y) { screenTop = y; }
	virtual void setScreenWidth(int width) { screenWidth = width; }
	virtual void setScreenHeight(int height) { screenHeight = height; }

	virtual int getScreenLeft() { return screenLeft; }
	virtual int getScreenTop() { return screenTop; }
	virtual int getScreenWidth() { return screenWidth; }
	virtual int getScreenHeight() { return screenHeight; }

	virtual bool isRunning() { return true; }

	//virtual void mainLoop();

protected:
	/**
	 * Screen position & dimension.
	 */
	int screenLeft;
	int screenTop;
	int screenWidth;
	int screenHeight;

	/**
	 * If true events are dispatched to the corresponding Lua functions.
	 */
	bool dispatchEvents;

	/**
	 * Listener called when an error message occurs.
	 */
	InterpreterErrorListener* interpreterErrorListener;
};

}

#endif
